package com.zlm.IO.ByteStream.BufferedStream;

import java.io.*;

/**
 * @author 13026
 */
public class BufferedStream_demo {
    /*
     * 字节缓冲流
     * BufferedInputStream BufferedOutputStream
     * */
    public static void main(String[] args) throws IOException {
        // 一次操作一个字节
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("D:\\myProject\\javaTest\\oneModule\\src\\com\\zlm\\IO\\ByteStream\\BufferedStream\\FilesPackage\\a.txt"));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("D:\\myProject\\javaTest\\oneModule\\src\\com\\zlm\\IO\\ByteStream\\BufferedStream\\FilesPackage\\a_copy.txt"));
        int b;
        while ((b = bis.read()) != -1) {
            bos.write(b);
        }
        bos.close();
        bis.close();

        // 一次操作多个字节
        BufferedInputStream bis2 = new BufferedInputStream(new FileInputStream("D:\\myProject\\javaTest\\oneModule\\src\\com\\zlm\\IO\\ByteStream\\BufferedStream\\FilesPackage\\a2.txt"));
        BufferedOutputStream bos2 = new BufferedOutputStream(new FileOutputStream("D:\\myProject\\javaTest\\oneModule\\src\\com\\zlm\\IO\\ByteStream\\BufferedStream\\FilesPackage\\a2_copy.txt"));
        byte[] bytes = new byte[1024];
        int length;
        while ((length = bis2.read(bytes)) != -1) {
            bos2.write(bytes, 0, length);
        }
        bos2.close();
        bis2.close();
    }
}
